import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    count: 200,
    num: 0,
  },
  mutations: {
    /* mutations的方法会接受state作为第一个参数 */
    increase(state) {
      state.count++;
    },
    increaseN(state, payload) {
      state.count += payload.n;
    },
  },
  actions: {
    // 默认参数是store 把commit解构出来
    increaseWait({ commit }) {
      setTimeout(() => {
        commit("increase");
      }, 1000);
    },
    increaseNWait({ commit }, payload) {
      setTimeout(() => {
        commit("increaseN", payload);
      }, 1000);
    },
  },
  getters: {},
});
